<?php


namespace app\model;


use think\exception\DbException;

class AppComment extends Base
{
    public function userInfo()
    {
        return $this->hasOne('AppWxUser', 'id', 'uid')->field('nickname,head_img');
    }

    /**
     * @param $size
     * @param $page
     * @param $where
     * @param null $obj
     * @return array
     */
    public function getList($size, $page, $where, $obj = null)
    {
        try {
            if ($obj == null) {
                $obj = $this;
            }
            $listObj = $obj->where($where)->order('create_time ASC')->field('id,rate,imgs,content,create_time,uid,goods_title')->paginate($size, false, ['page' => $page])->each(function ($value, $key) {
                $value->userInfo;
            })->toArray();
            return [
                'list' => $listObj['data'],
                'count' => $listObj['total']
            ];
        } catch (DbException $e) {
        }
        return ['list' => null, 'count' => 0];
    }
}